﻿<UserControl 
    x:Class="Imagin.Controls.Extended.GradientPicker"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Imagin.Controls.Extended"
    xmlns:Common="http://imagin.tech/imagin/common"
    xmlns:Controls.Common="http://imagin.tech/imagin/controls/common"
    mc:Ignorable="d" 
    d:DesignWidth="525"
    x:Name="PART_GradientEditor">
    <UserControl.Resources>
        <Common:AbbreviationAttributeConverter x:Key="AbbreviationAttributeConverter"/>
        <Common:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <Common:EnumToCollectionConverter x:Key="EnumToCollectionConverter"/>
    </UserControl.Resources>
    <Grid DataContext="{Binding ElementName=PART_GradientEditor}" Margin="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <ComboBox
            ItemsSource="{Binding Source={x:Type Common:GradientType}, Converter={StaticResource EnumToCollectionConverter}}"
            SelectedValue="{Binding GradientType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Mode=OneWay}"/>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
        <GroupBox 
            Grid.Row="1"
            Header="Bands"
            Margin="0,10,0,0">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>

                <Slider 
                    Grid.ColumnSpan="2" 
                    Height="22" 
                    Name="PART_BandsSlider" 
                    Margin="10,0"
                    IsSnapToTickEnabled="True"
                    VerticalAlignment="Center" 
                    TickPlacement="BottomRight" 
                    TickFrequency="1" 
                    Value="{Binding SelectedBand}"
                    SmallChange="1" 
                    Minimum="1"
                    Maximum="{Binding Bands, Mode=OneWay}"/>
                <Controls.Common:IntUpDown
                    Grid.Column="2"
                    Minimum="1"
                    Maximum="25"
                    Text="{Binding Bands, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                    Width="75"
                    VerticalAlignment="Center"/>
            
                <local:ColorChip 
                    Grid.Row="1" 
                    x:Name="PART_ColorChip"
                    Color="{Binding SelectedColor, Mode=TwoWay}"
                    VerticalAlignment="Center"/>
                <Slider
                    Grid.Column="1" 
                    Grid.Row="1"
                    Height="22" 
                    Margin="10"
                    IsSnapToTickEnabled="True"
                    TickPlacement="BottomRight" 
                    TickFrequency="0.01" 
                    SmallChange="0.01" 
                    LargeChange="0.05" 
                    Value="{Binding Offset}"
                    Maximum="1.0"
                    Minimum="0"
                    VerticalAlignment="Center"/>
                <Controls.Common:DoubleUpDown
                    Grid.Column="2"
                    Grid.Row="1"
                    Width="75"
                    Minimum="0"
                    Maximum="1.0"
                    Increment="0.01"
                    StringFormat="N2"
                    Text="{Binding Offset, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                    VerticalAlignment="Center"/>
            </Grid>
        </GroupBox>
        <Grid 
            Grid.Row="2"
            Margin="0,15,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="164"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <StackPanel
                Grid.RowSpan="2"
                Controls.Common:PanelExtensions.Spacing="0,0,0,15"
                Controls.Common:PanelExtensions.TrimLast="True"
                Margin="0,0,15,0">
                <local:AnglePicker
                    x:Name="PART_AnglePicker"
                    Angle="{Binding Angle}"
                    Height="96"
                    HorizontalAlignment="Center"
                    Radians="{Binding Radians}"
                    Width="96"/>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <ContentControl Margin="0,0,5,0">
                        <ContentControl.Style>
                            <Style TargetType="ContentControl">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding AngularUnit, RelativeSource={RelativeSource AncestorType={x:Type local:GradientPicker}}}" Value="Degree">
                                        <Setter Property="Content">
                                            <Setter.Value>
                                                <Controls.Common:DoubleUpDown
                                                    Minimum="-180"
                                                    Maximum="180"
                                                    StringFormat="N0"
                                                    Value="{Binding Angle}"/>
                                            </Setter.Value>
                                        </Setter>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding AngularUnit, RelativeSource={RelativeSource AncestorType={x:Type local:GradientPicker}}}" Value="Radian">
                                        <Setter Property="Content">
                                            <Setter.Value>
                                                <Controls.Common:DoubleUpDown
                                                    Minimum="-180"
                                                    Maximum="180"
                                                    StringFormat="N6"
                                                    Value="{Binding Radians}"/>
                                            </Setter.Value>
                                        </Setter>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </ContentControl.Style>
                    </ContentControl>
                    <ComboBox
                        Grid.Column="1"
                        ItemsSource="{Binding Source={x:Type Common:AngularUnit}, Converter={StaticResource EnumToCollectionConverter}}"
                        SelectedValue="{Binding AngularUnit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Mode=OneWay, Converter={StaticResource AbbreviationAttributeConverter}}"/>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>
                </Grid>
                <ComboBox
                    ItemsSource="{Binding Source={x:Type Common:GradientPosition}, Converter={StaticResource EnumToCollectionConverter}}"
                    SelectedValue="{Binding GradientPosition, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Mode=OneWay}"/>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
            </StackPanel>
            <Controls.Common:CheckerBoard
                Grid.Column="1"
                BorderBrush="{Binding PreviewBorderBrush}"
                BorderThickness="{Binding PreviewBorderThickness}"
                CheckerForeground="LightGray"
                Visibility="{Binding ShowPreview, Converter={StaticResource BooleanToVisibilityConverter}}">
                <Rectangle Fill="{Binding Gradient}"/>
            </Controls.Common:CheckerBoard>
        </Grid>
        <Grid 
            Grid.Row="3"
            Margin="0,10,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>

            <Label 
                Grid.Row="2"
                Content="Opacity" 
                VerticalAlignment="Center"/>
            <Slider 
                Grid.Column="1" 
                Grid.Row="2"
                Height="22" 
                Margin="10,0"
                IsSnapToTickEnabled="True"
                VerticalAlignment="Center" 
                TickPlacement="BottomRight" 
                TickFrequency="0.01" 
                Value="{Binding Gradient.Opacity}"
                SmallChange="0.05" 
                Minimum="0"
                Maximum="1"/>
            <Controls.Common:DoubleUpDown
                Grid.Column="2"
                Grid.Row="2"
                Increment="0.01"
                Minimum="0"
                Maximum="1"
                Text="{Binding Gradient.Opacity, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                Width="75"
                VerticalAlignment="Center"/>
        </Grid>
    </Grid>
</UserControl>
